/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.a;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.login.plugin.g.o;
import com.qihoo.gamecenter.sdk.login.plugin.h.d;
import com.qihoo.gamecenter.sdk.login.plugin.login.c;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;

public class a {
    private Context b;
    private Intent c;
    private com.qihoo.a.a.a d;
    protected ArrayList a = new ArrayList(1);
    private boolean e = false;

    public a(Context paramContext, Intent paramIntent) {
        this.b = paramContext;
        this.c = paramIntent;
    }

    public boolean a() {
        return (this.d != null);
    }

    public void a(com.qihoo.a.a.a parama) {
        this.d = parama;
    }

    public com.qihoo.a.a.a b() {
        return this.d;
    }

    public boolean c() {
        return this.e;
    }

    public void a(e parame, c paramc, boolean paramBoolean) {
        g localg = b(parame, paramc, paramBoolean);
        this.a.add(localg);
        localg.a();
    }

    private g b(e parame, c paramc, boolean paramBoolean) {
        Object localObject;
        if ((this.d != null) && (!(paramBoolean)) && (paramc.j() != 4))
            localObject = new b(paramc, parame);
        else
            localObject = new a(paramc, parame);
        return ((g) localObject);
    }

    public void a(n paramn) {
        new Thread(paramn) {
            // ERROR //
            public void run() {
                // Byte code:
                //   0: aload_0
                //   1: getfield 28	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:b	Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;
                //   4: invokestatic 30	com/qihoo/gamecenter/sdk/login/plugin/a/a:a	(Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;)Lcom/qihoo/a/a/a;
                //   7: ifnull +252 -> 259
                //   10: aload_0
                //   11: getfield 28	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:b	Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;
                //   14: invokestatic 31	com/qihoo/gamecenter/sdk/login/plugin/a/a:b	(Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;)Landroid/content/Context;
                //   17: invokevirtual 29	android/content/Context:getPackageName	()Ljava/lang/String;
                //   20: astore_1
                //   21: aload_0
                //   22: getfield 28	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:b	Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;
                //   25: invokestatic 31	com/qihoo/gamecenter/sdk/login/plugin/a/a:b	(Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;)Landroid/content/Context;
                //   28: aload_0
                //   29: getfield 28	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:b	Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;
                //   32: invokestatic 32	com/qihoo/gamecenter/sdk/login/plugin/a/a:c	(Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;)Landroid/content/Intent;
                //   35: invokestatic 33	com/qihoo/gamecenter/sdk/login/plugin/h/a:a	(Landroid/content/Context;Landroid/content/Intent;)Ljava/lang/String;
                //   38: astore_2
                //   39: iconst_2
                //   40: anewarray 22	java/lang/String
                //   43: astore_3
                //   44: aload_0
                //   45: getfield 28	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:b	Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;
                //   48: invokestatic 30	com/qihoo/gamecenter/sdk/login/plugin/a/a:a	(Lcom/qihoo/gamecenter/sdk/login/plugin/a/a;)Lcom/qihoo/a/a/a;
                //   51: aload_1
                //   52: aload_2
                //   53: bipush 10
                //   55: aload_3
                //   56: invokeinterface 44 5 0
                //   61: istore 4
                //   63: ldc 2
                //   65: iconst_1
                //   66: anewarray 21	java/lang/Object
                //   69: dup
                //   70: iconst_0
                //   71: new 23	java/lang/StringBuilder
                //   74: dup
                //   75: invokespecial 37	java/lang/StringBuilder:<init>	()V
                //   78: ldc 3
                //   80: invokevirtual 39	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
                //   83: iload 4
                //   85: invokevirtual 38	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
                //   88: invokevirtual 40	java/lang/StringBuilder:toString	()Ljava/lang/String;
                //   91: aastore
                //   92: invokestatic 34	com/qihoo/gamecenter/sdk/login/plugin/h/e:a	(Ljava/lang/String;[Ljava/lang/Object;)V
                //   95: iload 4
                //   97: ifne +148 -> 245
                //   100: ldc 2
                //   102: iconst_1
                //   103: anewarray 21	java/lang/Object
                //   106: dup
                //   107: iconst_0
                //   108: new 23	java/lang/StringBuilder
                //   111: dup
                //   112: invokespecial 37	java/lang/StringBuilder:<init>	()V
                //   115: ldc 9
                //   117: invokevirtual 39	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
                //   120: aload_3
                //   121: iconst_0
                //   122: aaload
                //   123: ifnull +9 -> 132
                //   126: aload_3
                //   127: iconst_0
                //   128: aaload
                //   129: goto +5 -> 134
                //   132: ldc 8
                //   134: invokevirtual 39	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
                //   137: invokevirtual 40	java/lang/StringBuilder:toString	()Ljava/lang/String;
                //   140: aastore
                //   141: invokestatic 34	com/qihoo/gamecenter/sdk/login/plugin/h/e:a	(Ljava/lang/String;[Ljava/lang/Object;)V
                //   144: ldc 2
                //   146: iconst_1
                //   147: anewarray 21	java/lang/Object
                //   150: dup
                //   151: iconst_0
                //   152: new 23	java/lang/StringBuilder
                //   155: dup
                //   156: invokespecial 37	java/lang/StringBuilder:<init>	()V
                //   159: ldc 10
                //   161: invokevirtual 39	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
                //   164: aload_3
                //   165: iconst_1
                //   166: aaload
                //   167: ifnull +9 -> 176
                //   170: aload_3
                //   171: iconst_1
                //   172: aaload
                //   173: goto +5 -> 178
                //   176: ldc 8
                //   178: invokevirtual 39	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
                //   181: invokevirtual 40	java/lang/StringBuilder:toString	()Ljava/lang/String;
                //   184: aastore
                //   185: invokestatic 34	com/qihoo/gamecenter/sdk/login/plugin/h/e:a	(Ljava/lang/String;[Ljava/lang/Object;)V
                //   188: aload_3
                //   189: iconst_1
                //   190: aaload
                //   191: astore 5
                //   193: new 26	org/json/JSONObject
                //   196: dup
                //   197: aload 5
                //   199: invokespecial 42	org/json/JSONObject:<init>	(Ljava/lang/String;)V
                //   202: astore 6
                //   204: aload 6
                //   206: ldc 5
                //   208: invokevirtual 43	org/json/JSONObject:getString	(Ljava/lang/String;)Ljava/lang/String;
                //   211: astore 7
                //   213: aload 7
                //   215: ldc 1
                //   217: invokevirtual 36	java/lang/String:split	(Ljava/lang/String;)[Ljava/lang/String;
                //   220: astore 8
                //   222: aload_0
                //   223: getfield 27	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:a	Lcom/qihoo/gamecenter/sdk/login/plugin/a/n;
                //   226: aload 8
                //   228: invokeinterface 45 2 0
                //   233: return
                //   234: astore 6
                //   236: ldc 4
                //   238: ldc 7
                //   240: aload 6
                //   242: invokestatic 35	com/qihoo/gamecenter/sdk/login/plugin/h/e:b	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
                //   245: goto +14 -> 259
                //   248: astore 4
                //   250: ldc 4
                //   252: ldc 6
                //   254: aload 4
                //   256: invokestatic 35	com/qihoo/gamecenter/sdk/login/plugin/h/e:b	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
                //   259: aload_0
                //   260: getfield 27	com/qihoo/gamecenter/sdk/login/plugin/a/a$1:a	Lcom/qihoo/gamecenter/sdk/login/plugin/a/n;
                //   263: aconst_null
                //   264: invokeinterface 45 2 0
                //   269: return
                //
                // Exception table:
                //   from	to	target	type
                //   193	233	234	org/json/JSONException
                //   44	233	248	java/lang/Exception
                //   234	245	248	java/lang/Exception
            }
        }.start();
    }

    public void a(i parami, String paramString) {
        new Thread(paramString, parami) {
            public void run() {
                if (a.a(a.this) != null) {
                    String str1 = a.b(a.this).getPackageName();
                    String str2 = com.qihoo.gamecenter.sdk.login.plugin.h.a.a(a.b(a.this), a.c(a.this));
                    String[] arrayOfString = new String[2];
                    try {
                        int i = a.a(a.this).a(str1, this.a, str2, arrayOfString);
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                                new Object[] { "AccountService.logout errno=" + i });
                        if (i == 0) {
                            com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "result[0]="
                                    + ((arrayOfString[0] != null) ? arrayOfString[0] : "null") });
                            com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "result[1]="
                                    + ((arrayOfString[1] != null) ? arrayOfString[1] : "null") });
                            this.b.a(true, this.a);
                            return;
                        }
                    } catch (Exception localException) {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.b("AccountAgent", "remove remote user error!",
                                localException);
                    }
                }
                this.b.a(false, this.a);
            }
        }.start();
    }

    private class a extends g {
        private com.qihoo.gamecenter.sdk.login.plugin.g.b d = new com.qihoo.gamecenter.sdk.login.plugin.g.b() {
            public void a(String paramString, Context paramContext) {
                super.a(paramString, paramContext);
                a(paramContext, a());
            }

            private void a(Context paramContext, String paramString) {
                int i = 1;
                if (!(TextUtils.isEmpty(paramString))) {
                    com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                            new Object[] { "LoginReqToSdk login result=" + paramString });
                    try {
                        JSONObject localJSONObject1 = new JSONObject(paramString);
                        int j = localJSONObject1.optInt("errno", -1);
                        if (j == 0) {
                            JSONObject localJSONObject3 = localJSONObject1.optJSONObject("user");
                            if ((localJSONObject3 != null) && (localJSONObject3.has("qid")))
                                d.a(paramContext, localJSONObject3.getString("qid"));
                            a.a.a(a.a.this);
                        }
                        else {
                            a.a.this.b(localJSONObject1);
                        }
                        i = 0;
                    } catch (JSONException localJSONException) {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.b("AccountAgent", "handle login res error!",
                                localJSONException);
                    }
                }
                else {
                    a.a(a.this, true);
                }
                if (i == 0)
                    return;
                com.qihoo.gamecenter.sdk.login.plugin.h.e
                        .a("AccountAgent", new Object[] { "get qt failed in sdk req" });
                JSONObject localJSONObject2 = a.a.this.a(true);
                a.a.this.b(localJSONObject2);
            }

            public void a(JSONObject paramJSONObject, Context paramContext) {
                try {
                    if (paramJSONObject != null) {
                        int i = paramJSONObject.getInt("error_code");
                        if ((i != 0) && (TextUtils.isEmpty(d.b())))
                            a(paramContext, i, paramJSONObject.getString("error_msg"), true);
                    }
                } catch (JSONException localJSONException) {
                    com.qihoo.gamecenter.sdk.login.plugin.h.e
                            .b("AccountAgent", "show toast error!", localJSONException);
                }
            }
        };
        private com.qihoo.gamecenter.sdk.login.plugin.g.b e = new com.qihoo.gamecenter.sdk.login.plugin.g.b() {
            public void a(String paramString, Context paramContext) {
                super.a(paramString, paramContext);
                a(a());
            }

            private void a(String paramString) {
                int i = 1;
                if (!(TextUtils.isEmpty(paramString))) {
                    com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                            new Object[] { "LoginReqToSdk auth result=" + paramString });
                    try {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "auth resultJson="
                                + paramString });
                        JSONObject localJSONObject1 = new JSONObject(paramString);
                        JSONObject localJSONObject3;
                        if (localJSONObject1.has("access_token")) {
                            localJSONObject3 = new JSONObject();
                            localJSONObject3.put("errno", 0);
                            localJSONObject3.put("data", localJSONObject1);
                            a.a.this.a(localJSONObject3);
                            i = 0;
                        }
                        else if (localJSONObject1.has("error_code")) {
                            localJSONObject3 = new JSONObject();
                            String str1 = localJSONObject1.getString("error_code");
                            String str2 = localJSONObject1.optString("error", "");
                            localJSONObject3.put("errno", Integer.valueOf(str1));
                            localJSONObject3.put("errmsg", str2);
                            a.a.this.b(localJSONObject3);
                            i = 0;
                        }
                        else if (localJSONObject1.has("errno")) {
                            a.a.this.b(localJSONObject1);
                            i = 0;
                        }
                    } catch (Exception localException) {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.b("AccountAgent", "reg sdk handle token error!",
                                localException);
                    }
                }
                else {
                    a.a(a.this, true);
                }
                if (i == 0)
                    return;
                com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                        new Object[] { "get token failed in sdk req" });
                JSONObject localJSONObject2 = a.a.this.a(false);
                a.a.this.b(localJSONObject2);
            }
        };

        public a(c paramc, e parame) {
            super(-1L, paramc, parame);
        }

        public void a() {
            com.qihoo.gamecenter.sdk.login.plugin.login.b.a(a.b(a.this), a.c(a.this), this.b, this.d);
        }

        private void c() {
            com.qihoo.gamecenter.sdk.login.plugin.login.b.b(a.b(a.this), a.c(a.this), this.b, this.e);
        }

        protected void b() {
            a.this.a.remove(this);
        }
    }

    private class b extends g {
        private o d = new o() {
            public void a(String paramString, Context paramContext) {
                a(paramString);
            }

            private void a(String paramString) {
                int i = 1;
                if (!(TextUtils.isEmpty(paramString))) {
                    com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                            new Object[] { "LoginReqToService result=" + paramString });
                    try {
                        JSONObject localJSONObject1 = new JSONObject(paramString);
                        int j = localJSONObject1.optInt("errno", -1);
                        if (j == 0) {
                            JSONObject localJSONObject3 = a.b.a(a.b.this, paramString);
                            if ((localJSONObject3 != null) && (localJSONObject3.has("qid")))
                                d.a(a.b(a.this), localJSONObject3.getString("qid"));
                            com.qihoo.gamecenter.sdk.login.plugin.login.b.b(a.b(a.this), a.c(a.this), a.b.this.b,
                                    a.b.a(a.b.this));
                        }
                        else {
                            if ((((j == 5099) || (j == 99102)))
                                    && (((!(TextUtils.isEmpty(a.b.this.b.c())))
                                            || (!(TextUtils.isEmpty(a.b.this.b.h()))) || (!(TextUtils
                                                .isEmpty(a.b.this.b.i())))))) {
                                a.b.this.b();
                                if (!(TextUtils.isEmpty(a.b.this.b.c())))
                                    a.b.this.b.a(2);
                                else if (!(TextUtils.isEmpty(a.b.this.b.h())))
                                    a.b.this.b.a(3);
                                else if (!(TextUtils.isEmpty(a.b.this.b.i())))
                                    a.b.this.b.a(4);
                                a.this.a(a.b.this.c, a.b.this.b, true);
                                return;
                            }
                            if (!(localJSONObject1.has("errno")))
                                localJSONObject1.put("errno", -1);
                            a.b.this.b(localJSONObject1);
                        }
                        i = 0;
                    } catch (JSONException localJSONException) {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.b("AccountAgent", "handleAuthResult error!",
                                localJSONException);
                    }
                }
                if (i == 0)
                    return;
                com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "get qt failed!" });
                JSONObject localJSONObject2 = a.b.this.a(true);
                a.b.this.b(localJSONObject2);
            }
        };
        private com.qihoo.gamecenter.sdk.login.plugin.g.b e = new com.qihoo.gamecenter.sdk.login.plugin.g.b() {
            public void a(String paramString, Context paramContext) {
                super.a(paramString, paramContext);
                a(a());
            }

            private void a(String paramString) {
                int i = 1;
                if (!(TextUtils.isEmpty(paramString))) {
                    com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent",
                            new Object[] { "LoginReqToSdk auth result=" + paramString });
                    try {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "auth resultJson="
                                + paramString });
                        JSONObject localJSONObject1 = new JSONObject(paramString);
                        JSONObject localJSONObject3;
                        if (localJSONObject1.has("access_token")) {
                            localJSONObject3 = new JSONObject();
                            localJSONObject3.put("errno", 0);
                            localJSONObject3.put("data", localJSONObject1);
                            a.b.this.a(localJSONObject3);
                            i = 0;
                        }
                        else if (localJSONObject1.has("error_code")) {
                            localJSONObject3 = new JSONObject();
                            String str1 = localJSONObject1.getString("error_code");
                            String str2 = localJSONObject1.optString("error", "");
                            localJSONObject3.put("errno", Integer.valueOf(str1));
                            localJSONObject3.put("errmsg", str2);
                            a.b.this.b(localJSONObject3);
                            i = 0;
                        }
                        else if (localJSONObject1.has("errno")) {
                            a.b.this.b(localJSONObject1);
                            i = 0;
                        }
                    } catch (Exception localException) {
                        com.qihoo.gamecenter.sdk.login.plugin.h.e.b("AccountAgent", "handle Token Result error!",
                                localException);
                    }
                }
                else {
                    a.a(a.this, true);
                }
                if (i == 0)
                    return;
                com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", new Object[] { "auth failed!" });
                JSONObject localJSONObject2 = a.b.this.a(false);
                a.b.this.b(localJSONObject2);
            }
        };

        public b(c paramc, e parame) {
            super(System.currentTimeMillis(), paramc, parame);
        }

        public void a() {
            com.qihoo.gamecenter.sdk.login.plugin.login.b.a(a.b(a.this), a.c(a.this), this.b, a.a(a.this), this.d);
        }

        protected void b() {
            a.this.a.remove(this);
        }

        private JSONObject a(String paramString) {
            try {
                JSONObject localJSONObject1 = new JSONObject(paramString);
                JSONObject localJSONObject2 = localJSONObject1.optJSONObject("user");
                return localJSONObject2;
            } catch (Exception localException) {
                com.qihoo.gamecenter.sdk.login.plugin.h.e.a("AccountAgent", "getUserJson error", localException);
            }
            return null;
        }
    }
}